-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add NewType #1939
Add NewType #1939
Conversation
... | ||
|
||
However, at runtime, ``NewType('Derived', Base)`` will return a dummy function that | ||
simply returns its argument. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to show this by example, e.g.
def Derived(_x):
return _x
|
||
def get_newtype_declaration(self, s: AssignmentStmt) -> Optional[CallExpr]: | ||
"""Returns the Newtype() call statement if `s` is a newtype declaration | ||
or None otherwise.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this docstring follow the PEP 257 recommendation?
Done with the first round of code review. Hopefully it's as thorough as you requested! :-) |
|
||
.. code-block:: python | ||
|
||
def Derived(_x: Base) -> Base: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is runtime, IMO it's better not to annotate it at all: just def Derived(_x): return _x
.
Thanks for writing such great documentation! |
This pull request implements
NewType
as described in PEP 484 and in issue #1284. It also adds a variety of test cases to verifyNewType
works correctly when used and misused and adds information about usingNewType
to the mypy docs.This pull request resolves #1284.