Skip to content

Use pyversion variable to change bytes checking for python 3 less than 3.5#2191

Merged
gvanrossum merged 17 commits into
python:masterfrom
buckbaskin:addPyversion2
Oct 5, 2016
Merged

Use pyversion variable to change bytes checking for python 3 less than 3.5#2191
gvanrossum merged 17 commits into
python:masterfrom
buckbaskin:addPyversion2

Conversation

@buckbaskin

Copy link
Copy Markdown
Contributor

This is based on a TODO from pull request #2168 to fix the behavior for checking bytes in Python 3 when the minor version is less than 3.5. Per #2168, bytes formatting in Python 3 is only supported in 3.5 and up.

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry to have led you down the garden path, I think there's a much simpler approach. (But now you know your way around more of the code!)

Comment thread mypy/checker.py Outdated
Type check mypy source files that have been semantically analyzed.
"""

pyversion = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add a type annotation here

Comment thread mypy/checkexpr.py Outdated
This class works closely together with checker.TypeChecker.
"""

pyversion = None # type: Tuple[int, int]

@gvanrossum gvanrossum Sep 28, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And here you can use self.chk.options.

Comment thread mypy/build.py Outdated
self.modules = self.semantic_analyzer.modules
self.semantic_analyzer_pass3 = ThirdPass(self.modules, self.errors)
self.type_checker = TypeChecker(self.errors, self.modules)
self.type_checker = TypeChecker(self.errors, self.modules, options.python_version)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You shouldn't need this -- you can access the version already via self.options.python_version.

Comment thread mypy/checkstrformat.py Outdated
chk: 'mypy.checker.TypeChecker',
msg: MessageBuilder) -> None:
msg: MessageBuilder,
pyversion: Tuple[int, int]) -> None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can just pull the version out of chk.options.

Comment thread mypy/checkstrformat.py Outdated
expression: str % replacements
"""
if isinstance(str, BytesExpr) and self.pyversion[0] == 3 and self.pyversion[1] < 5:
assert False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this is the right approach. It's probably better to move the version check to whatever calls check_str_interpolation(), so that it doesn't even get called for bytes if pyversion < 3.5, and then the fallback logic in the caller (which just maps '%' to a call to __mod__) will take over.

@gvanrossum gvanrossum changed the title Use pyversion variable to change bytes checking for python 3 less than 3.5 [needs changes] Use pyversion variable to change bytes checking for python 3 less than 3.5 Sep 29, 2016
@gvanrossum gvanrossum merged commit 30bd4c8 into python:master Oct 5, 2016
@gvanrossum

gvanrossum commented Oct 5, 2016

Copy link
Copy Markdown
Member

So I forgot to remove the "[needs changes]" and ended up amending the commit locally and doing a "git push -f". Hopefully this won't inconvenience too many people... New commit is 7e2b3b4

@gvanrossum gvanrossum changed the title [needs changes] Use pyversion variable to change bytes checking for python 3 less than 3.5 Use pyversion variable to change bytes checking for python 3 less than 3.5 Oct 5, 2016
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.

2 participants