Skip to content

Conversation

@z33ky
Copy link
Contributor

@z33ky z33ky commented Dec 15, 2016

Adds special methods for object as per #773.

3.6 also added __set_name__, but I'm uncertain if simply creating the directory stdlib/3.6 would suffice to add 3.6-specific type hints.

There are also still missing special methods, like __prepare__: I'm just confused to which class they belong.

Copy link
Contributor

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these didn't seem right when I tried them with object() instances. How did you come up with this set of methods?

def __setattr__(self, name: str, value: Any) -> None: ...
def __eq__(self, o: object) -> bool: ...
def __ne__(self, o: object) -> bool: ...
def __lt__(self, o: object) -> bool: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 4 definitions will break mypy. It's best to leave them out and potentially file a separate issue about these.

def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __hash__(self) -> int: ...
def __del__(self) -> None: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem to exist in Python 3.5.1: __del__, __bytes__, __bool__, __getattr__, __get__, __set__.

def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __hash__(self) -> int: ...
def __del__(self) -> None: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to exist.


def __get__(self, instance: Optional[object], owner: Type) -> Any: ...
def __set__(self, instance: object, value: Any) -> None: ...
def __delete__(self, instance: object) -> None: ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These don't seem to exist: __get__, __set__ and __delete__

@JukkaL
Copy link
Contributor

JukkaL commented Dec 15, 2016

If you looked up these from documentation, you should be aware of that (Python) documentation is not to be trusted as a source of truth when creating stubs -- docs tend to have too many inaccuracies and outright errors.

@z33ky
Copy link
Contributor Author

z33ky commented Dec 15, 2016

Yeah I tried looking at the CPython code, but I didn't quite get what is happening there.

I checked for existence of the methods with the interpreter and removed the ones which failed.

The 4 comparison operators are taken out. A pull request for mypy, which would allow defining them, is here: python/mypy#2584.

@ambv ambv force-pushed the master branch 10 times, most recently from 63ba0ab to 7853c26 Compare December 23, 2016 00:12
@gvanrossum
Copy link
Member

I've added __format__ to the PY2 version as well, and removed the redundant float.__format__.

Though maybe it should have the argument type AnyStr? Or Union[str, Text]? I have to think about that.

There are also some redundant definitions of __format__ in other modules now. Do you want to try and clean those up as well?

@gvanrossum
Copy link
Member

@JukkaL can you approve and/or merge?

@JukkaL
Copy link
Contributor

JukkaL commented Jan 4, 2017

Thanks for the updates!

__format__ should perhaps use AnyStr but I'll leave this to a future PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants