Skip to content
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

PEP 591: Adding a final qualifier to typing #990

Merged
merged 5 commits into from
Apr 13, 2019

Conversation

msullivan
Copy link
Contributor

Initial draft of proposal to add a final qualifier to the typing module

@gvanrossum gvanrossum merged commit f3b44fb into python:master Apr 13, 2019
@msullivan msullivan deleted the final branch April 13, 2019 00:18
subclasses. (``@property`` can make an attribute read-only but
does not prevent overriding)
* Allowing a name to be used in situations where ordinarily a literal
is expected (for example as a file name for ``NamedTuple``, a tuple
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I'm late to the party, but I'm guessing "file name" is a typo for "field name".

@final
def method(self, x=None):
...

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps say that use of final on a non-method function is an error.

for x in [1, 2, 3]:
FOO: Final = x # Error: Cannot use Final inside a loop

error: Cannot use Final inside a loop
Copy link
Member

Choose a reason for hiding this comment

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

Stray line

ncoghlan pushed a commit to ncoghlan/peps that referenced this pull request May 7, 2019
@sproshev
Copy link

Is it possible to use Final in type comments?

@ilevkivskyi
Copy link
Member

Yes.

@gvanrossum
Copy link
Member

Maybe there should be an example of that somewhere? (At least in the PEP? And even Python 3 code might want to use type comments if it's straddling with 2.7.)

@msullivan
Copy link
Contributor Author

I'll make a PR soon

@sproshev
Copy link

In the following sample mypy does not raise an error for y:

from typing_extensions import Final

x: Final[int] = 1
x: Final[str] = "str"

def foo():
    y: Final[int] = 1
    y: Final[str] = "str"

Is it a mypy bug or this case is allowed by PEP?

@ilevkivskyi
Copy link
Member

@sproshev How about adding an annotation to foo() or using --check-untyped-defs?

Also please don't spam in this PR. If you have questions, ask them on typing Gitter.

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

Successfully merging this pull request may close these issues.

6 participants