Skip to content

Commit 8ad8381

Browse files
authored
Merge pull request #858 from hippo91/fix_python39_new
Fix python39
2 parents 969a5cf + a35ff54 commit 8ad8381

File tree

7 files changed

+61
-5
lines changed

7 files changed

+61
-5
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
env: TOXENV=py37
2020
- python: 3.8
2121
env: TOXENV=py38
22+
- python: 3.9
23+
env: TOXENV=py39
2224
before_install:
2325
- python --version
2426
- uname -a

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ astroid's ChangeLog
66
What's New in astroid 2.5.0?
77
============================
88
Release Date: TBA
9+
* Add `python 3.9` support.
10+
911
* The flat attribute of ``numpy.ndarray`` is now inferred as an ``numpy.ndarray`` itself.
1012
It should be a ``numpy.flatiter`` instance, but this class is not yet available in the numpy brain.
1113

appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ environment:
1313
- PYTHON: "C:\\Python37"
1414
TOXENV: "py37"
1515

16+
- PYTHON: "C:\\Python38"
17+
TOXENV: "py38"
18+
1619
init:
1720
- ps: echo $env:TOXENV
1821
- ps: ls C:\Python*

astroid/arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def infer_argument(self, funcnode, name, context):
173173

174174
# Too many arguments given and no variable arguments.
175175
if len(self.positional_arguments) > len(funcnode.args.args):
176-
if not funcnode.args.vararg:
176+
if not funcnode.args.vararg and not funcnode.args.posonlyargs:
177177
raise exceptions.InferenceError(
178178
"Too many positional arguments "
179179
"passed to {func!r} that does "

astroid/brain/brain_namedtuple_enum.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ def infer_typing_namedtuple_class(class_node, context=None):
399399
return iter((generated_class_node,))
400400

401401

402+
def infer_typing_namedtuple_function(node, context=None):
403+
"""
404+
Starting with python3.9, NamedTuple is a function of the typing module.
405+
The class NamedTuple is build dynamically through a call to `type` during
406+
initialization of the `_NamedTuple` variable.
407+
"""
408+
klass = extract_node(
409+
"""
410+
from typing import _NamedTuple
411+
_NamedTuple
412+
"""
413+
)
414+
return klass.infer(context)
415+
416+
402417
def infer_typing_namedtuple(node, context=None):
403418
"""Infer a typing.NamedTuple(...) call."""
404419
# This is essentially a namedtuple with different arguments
@@ -450,6 +465,11 @@ def infer_typing_namedtuple(node, context=None):
450465
MANAGER.register_transform(
451466
nodes.ClassDef, inference_tip(infer_typing_namedtuple_class), _has_namedtuple_base
452467
)
468+
MANAGER.register_transform(
469+
nodes.FunctionDef,
470+
inference_tip(infer_typing_namedtuple_function),
471+
lambda node: node.name == "NamedTuple" and node.parent.name == "typing",
472+
)
453473
MANAGER.register_transform(
454474
nodes.Call, inference_tip(infer_typing_namedtuple), _looks_like_typing_namedtuple
455475
)

tests/unittest_inference.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5655,6 +5655,10 @@ def test_custom_decorators_for_classmethod_and_staticmethods(code, obj, obj_type
56555655

56565656

56575657
@pytest.mark.skipif(sys.version_info < (3, 8), reason="Needs dataclasses available")
5658+
@pytest.mark.skipif(
5659+
sys.version_info >= (3, 9),
5660+
reason="Exact inference with dataclasses (replace function) in python3.9",
5661+
)
56585662
def test_dataclasses_subscript_inference_recursion_error():
56595663
code = """
56605664
from dataclasses import dataclass, replace
@@ -5675,6 +5679,31 @@ class ProxyConfig:
56755679
assert helpers.safe_infer(node) is None
56765680

56775681

5682+
@pytest.mark.skipif(
5683+
sys.version_info < (3, 9),
5684+
reason="Exact inference with dataclasses (replace function) in python3.9",
5685+
)
5686+
def test_dataclasses_subscript_inference_recursion_error_39():
5687+
code = """
5688+
from dataclasses import dataclass, replace
5689+
5690+
@dataclass
5691+
class ProxyConfig:
5692+
auth: str = "/auth"
5693+
5694+
5695+
a = ProxyConfig("")
5696+
test_dict = {"proxy" : {"auth" : "", "bla" : "f"}}
5697+
5698+
foo = test_dict['proxy']
5699+
replace(a, **test_dict['proxy']) # This fails
5700+
"""
5701+
node = extract_node(code)
5702+
infer_val = helpers.safe_infer(node)
5703+
assert isinstance(infer_val, Instance)
5704+
assert infer_val.pytype() == ".ProxyConfig"
5705+
5706+
56785707
def test_self_reference_infer_does_not_trigger_recursion_error():
56795708
# Prevents https://github.com/PyCQA/pylint/issues/1285
56805709
code = """

tox.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py35, py36, py37, py38, pypy, pylint
2+
envlist = py35, py36, py37, py38, py39, pypy, pylint
33
skip_missing_interpreters = true
44

55
[testenv:pylint]
@@ -18,9 +18,9 @@ deps =
1818
; we have a brain for nose
1919
; we use pytest for tests
2020
nose
21-
py35,py36,py37: numpy
22-
py35,py36,py37: attr
23-
py35,py36,py37: typed_ast>=1.4.0,<1.5
21+
py35,py36,py37,py38,py39: numpy
22+
py35,py36,py37,py38,py39: attr
23+
py35,py36,py37,py38,py39: typed_ast>=1.4.0,<1.5
2424
pytest
2525
python-dateutil
2626
pypy: singledispatch

0 commit comments

Comments
 (0)