Compare commits
10 Commits
1cfab5770c
...
182d961cf8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
182d961cf8 | ||
|
|
23a41fe937 | ||
|
|
45827baee3 | ||
|
|
b5dd1e53d9 | ||
|
|
8ffa8ba208 | ||
|
|
516636b44e | ||
|
|
9c873af1c6 | ||
|
|
ff8fa56ee2 | ||
|
|
8132bedb44 | ||
|
|
df193736c6 |
@ -0,0 +1,75 @@
|
||||
From 13cad915e6b181b2f6a85efc2ead4856b23bccc0 Mon Sep 17 00:00:00 2001
|
||||
From: Angus L'Herrou <piraka@brandeis.edu>
|
||||
Date: Tue, 5 Oct 2021 18:44:29 -0400
|
||||
Subject: [PATCH] Detect typing module attributes with 'import typing as
|
||||
<name>' (#632)
|
||||
|
||||
* added functionality to detect typing module attributes with 'import typing as <name>'
|
||||
|
||||
* remove async keyword from test_aliased_import
|
||||
---
|
||||
pyflakes/checker.py | 12 +++++++++++-
|
||||
pyflakes/test/test_type_annotations.py | 17 +++++++++++++++++
|
||||
2 files changed, 28 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
|
||||
index 6fafe89..45c7a4a 100644
|
||||
--- a/pyflakes/checker.py
|
||||
+++ b/pyflakes/checker.py
|
||||
@@ -720,6 +720,16 @@ def _is_typing_helper(node, is_name_match_fn, scope_stack):
|
||||
|
||||
return False
|
||||
|
||||
+ def _module_scope_is_typing(name):
|
||||
+ for scope in reversed(scope_stack):
|
||||
+ if name in scope:
|
||||
+ return (
|
||||
+ isinstance(scope[name], Importation) and
|
||||
+ scope[name].fullName in TYPING_MODULES
|
||||
+ )
|
||||
+
|
||||
+ return False
|
||||
+
|
||||
return (
|
||||
(
|
||||
isinstance(node, ast.Name) and
|
||||
@@ -727,7 +737,7 @@ def _is_typing_helper(node, is_name_match_fn, scope_stack):
|
||||
) or (
|
||||
isinstance(node, ast.Attribute) and
|
||||
isinstance(node.value, ast.Name) and
|
||||
- node.value.id in TYPING_MODULES and
|
||||
+ _module_scope_is_typing(node.value.id) and
|
||||
is_name_match_fn(node.attr)
|
||||
)
|
||||
)
|
||||
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
|
||||
index 6a66bcd..f3b6c24 100644
|
||||
--- a/pyflakes/test/test_type_annotations.py
|
||||
+++ b/pyflakes/test/test_type_annotations.py
|
||||
@@ -121,6 +121,23 @@ class TestTypeAnnotations(TestCase):
|
||||
def f(self, x): return x
|
||||
""")
|
||||
|
||||
+ def test_aliased_import(self):
|
||||
+ """Detect when typing is imported as another name"""
|
||||
+ self.flakes("""
|
||||
+ import typing as t
|
||||
+
|
||||
+ @t.overload
|
||||
+ def f(s): # type: (None) -> None
|
||||
+ pass
|
||||
+
|
||||
+ @t.overload
|
||||
+ def f(s): # type: (int) -> int
|
||||
+ pass
|
||||
+
|
||||
+ def f(s):
|
||||
+ return s
|
||||
+ """)
|
||||
+
|
||||
def test_not_a_typing_overload(self):
|
||||
"""regression test for @typing.overload detection bug in 2.1.0"""
|
||||
self.flakes("""
|
||||
--
|
||||
2.42.0.windows.2
|
||||
|
||||
139
0001-add-support-for-match-statement-630.patch
Normal file
139
0001-add-support-for-match-statement-630.patch
Normal file
@ -0,0 +1,139 @@
|
||||
From cf75971656d9a04faa1b5aeaeb776da3567b8041 Mon Sep 17 00:00:00 2001
|
||||
From: Anthony Sottile <asottile@umich.edu>
|
||||
Date: Tue, 5 Oct 2021 15:37:44 -0700
|
||||
Subject: [PATCH] add support for match statement (#630)
|
||||
|
||||
---
|
||||
pyflakes/checker.py | 14 ++++++-
|
||||
pyflakes/test/test_match.py | 83 +++++++++++++++++++++++++++++++++++++
|
||||
2 files changed, 96 insertions(+), 1 deletion(-)
|
||||
create mode 100644 pyflakes/test/test_match.py
|
||||
|
||||
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
|
||||
index 135ad33..6fafe89 100644
|
||||
--- a/pyflakes/checker.py
|
||||
+++ b/pyflakes/checker.py
|
||||
@@ -275,7 +275,8 @@ def iter_child_nodes(node, omit=None, _fields_order=_FieldsOrder()):
|
||||
yield field
|
||||
elif isinstance(field, list):
|
||||
for item in field:
|
||||
- yield item
|
||||
+ if isinstance(item, ast.AST):
|
||||
+ yield item
|
||||
|
||||
|
||||
def convert_to_value(item):
|
||||
@@ -691,6 +692,8 @@ def getNodeName(node):
|
||||
return node.id
|
||||
if hasattr(node, 'name'): # an ExceptHandler node
|
||||
return node.name
|
||||
+ if hasattr(node, 'rest'): # a MatchMapping node
|
||||
+ return node.rest
|
||||
|
||||
|
||||
TYPING_MODULES = frozenset(('typing', 'typing_extensions'))
|
||||
@@ -2378,3 +2381,12 @@ class Checker(object):
|
||||
left = right
|
||||
|
||||
self.handleChildren(node)
|
||||
+
|
||||
+ MATCH = MATCH_CASE = MATCHCLASS = MATCHOR = MATCHSEQUENCE = handleChildren
|
||||
+ MATCHSINGLETON = MATCHVALUE = handleChildren
|
||||
+
|
||||
+ def _match_target(self, node):
|
||||
+ self.handleNodeStore(node)
|
||||
+ self.handleChildren(node)
|
||||
+
|
||||
+ MATCHAS = MATCHMAPPING = MATCHSTAR = _match_target
|
||||
diff --git a/pyflakes/test/test_match.py b/pyflakes/test/test_match.py
|
||||
new file mode 100644
|
||||
index 0000000..89826e3
|
||||
--- /dev/null
|
||||
+++ b/pyflakes/test/test_match.py
|
||||
@@ -0,0 +1,83 @@
|
||||
+from sys import version_info
|
||||
+
|
||||
+from pyflakes.test.harness import TestCase, skipIf
|
||||
+
|
||||
+
|
||||
+@skipIf(version_info < (3, 10), "Python >= 3.10 only")
|
||||
+class TestMatch(TestCase):
|
||||
+ def test_match_bindings(self):
|
||||
+ self.flakes('''
|
||||
+ def f():
|
||||
+ x = 1
|
||||
+ match x:
|
||||
+ case 1 as y:
|
||||
+ print(f'matched as {y}')
|
||||
+ ''')
|
||||
+ self.flakes('''
|
||||
+ def f():
|
||||
+ x = [1, 2, 3]
|
||||
+ match x:
|
||||
+ case [1, y, 3]:
|
||||
+ print(f'matched {y}')
|
||||
+ ''')
|
||||
+ self.flakes('''
|
||||
+ def f():
|
||||
+ x = {'foo': 1}
|
||||
+ match x:
|
||||
+ case {'foo': y}:
|
||||
+ print(f'matched {y}')
|
||||
+ ''')
|
||||
+
|
||||
+ def test_match_pattern_matched_class(self):
|
||||
+ self.flakes('''
|
||||
+ from a import B
|
||||
+
|
||||
+ match 1:
|
||||
+ case B(x=1) as y:
|
||||
+ print(f'matched {y}')
|
||||
+ ''')
|
||||
+ self.flakes('''
|
||||
+ from a import B
|
||||
+
|
||||
+ match 1:
|
||||
+ case B(a, x=z) as y:
|
||||
+ print(f'matched {y} {a} {z}')
|
||||
+ ''')
|
||||
+
|
||||
+ def test_match_placeholder(self):
|
||||
+ self.flakes('''
|
||||
+ def f():
|
||||
+ match 1:
|
||||
+ case _:
|
||||
+ print('catchall!')
|
||||
+ ''')
|
||||
+
|
||||
+ def test_match_singleton(self):
|
||||
+ self.flakes('''
|
||||
+ match 1:
|
||||
+ case True:
|
||||
+ print('true')
|
||||
+ ''')
|
||||
+
|
||||
+ def test_match_or_pattern(self):
|
||||
+ self.flakes('''
|
||||
+ match 1:
|
||||
+ case 1 | 2:
|
||||
+ print('one or two')
|
||||
+ ''')
|
||||
+
|
||||
+ def test_match_star(self):
|
||||
+ self.flakes('''
|
||||
+ x = [1, 2, 3]
|
||||
+ match x:
|
||||
+ case [1, *y]:
|
||||
+ print(f'captured: {y}')
|
||||
+ ''')
|
||||
+
|
||||
+ def test_match_double_star(self):
|
||||
+ self.flakes('''
|
||||
+ x = {'foo': 'bar', 'baz': 'womp'}
|
||||
+ match x:
|
||||
+ case {'foo': k1, **rest}:
|
||||
+ print(f'{k1=} {rest=}')
|
||||
+ ''')
|
||||
--
|
||||
2.42.0.windows.2
|
||||
|
||||
25
0001-fix-typo-annoation-annotation-636.patch
Normal file
25
0001-fix-typo-annoation-annotation-636.patch
Normal file
@ -0,0 +1,25 @@
|
||||
From 2e2dfb186569faed40fc93fad2ebf8c5e4b80301 Mon Sep 17 00:00:00 2001
|
||||
From: Yusuke Hayashi <yusuke8h@gmail.com>
|
||||
Date: Sat, 22 May 2021 12:34:08 +0900
|
||||
Subject: [PATCH] fix typo: annoation -> annotation (#636)
|
||||
|
||||
---
|
||||
pyflakes/test/test_type_annotations.py | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
|
||||
index f131034..6a66bcd 100644
|
||||
--- a/pyflakes/test/test_type_annotations.py
|
||||
+++ b/pyflakes/test/test_type_annotations.py
|
||||
@@ -531,7 +531,7 @@ class TestTypeAnnotations(TestCase):
|
||||
def test_type_cast_literal_str_to_str(self):
|
||||
# Checks that our handling of quoted type annotations in the first
|
||||
# argument to `cast` doesn't cause issues when (only) the _second_
|
||||
- # argument is a literal str which looks a bit like a type annoation.
|
||||
+ # argument is a literal str which looks a bit like a type annotation.
|
||||
self.flakes("""
|
||||
from typing import cast
|
||||
|
||||
--
|
||||
2.42.0.windows.2
|
||||
|
||||
42
0001-remove-old-and-unused-tracing-code-625.patch
Normal file
42
0001-remove-old-and-unused-tracing-code-625.patch
Normal file
@ -0,0 +1,42 @@
|
||||
From da197ee94e791640d82940396c19d2d82ca8defb Mon Sep 17 00:00:00 2001
|
||||
From: Terence Honles <terence@honles.com>
|
||||
Date: Thu, 20 May 2021 07:47:19 -0700
|
||||
Subject: [PATCH] remove old and unused "tracing" code (#625)
|
||||
|
||||
---
|
||||
pyflakes/checker.py | 5 -----
|
||||
1 file changed, 5 deletions(-)
|
||||
|
||||
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
|
||||
index 48d3841..135ad33 100644
|
||||
--- a/pyflakes/checker.py
|
||||
+++ b/pyflakes/checker.py
|
||||
@@ -868,7 +868,6 @@ class Checker(object):
|
||||
|
||||
nodeDepth = 0
|
||||
offset = None
|
||||
- traceTree = False
|
||||
_in_annotation = AnnotationState.NONE
|
||||
_in_deferred = False
|
||||
|
||||
@@ -1393,8 +1392,6 @@ class Checker(object):
|
||||
if self.offset and getattr(node, 'lineno', None) is not None:
|
||||
node.lineno += self.offset[0]
|
||||
node.col_offset += self.offset[1]
|
||||
- if self.traceTree:
|
||||
- print(' ' * self.nodeDepth + node.__class__.__name__)
|
||||
if self.futuresAllowed and not (isinstance(node, ast.ImportFrom) or
|
||||
self.isDocstring(node)):
|
||||
self.futuresAllowed = False
|
||||
@@ -1406,8 +1403,6 @@ class Checker(object):
|
||||
handler(node)
|
||||
finally:
|
||||
self.nodeDepth -= 1
|
||||
- if self.traceTree:
|
||||
- print(' ' * self.nodeDepth + 'end ' + node.__class__.__name__)
|
||||
|
||||
_getDoctestExamples = doctest.DocTestParser().get_examples
|
||||
|
||||
--
|
||||
2.42.0.windows.2
|
||||
|
||||
Binary file not shown.
BIN
pyflakes-2.3.1.tar.gz
Normal file
BIN
pyflakes-2.3.1.tar.gz
Normal file
Binary file not shown.
@ -1,15 +1,18 @@
|
||||
Name: pyflakes
|
||||
Version: 2.0.0
|
||||
Release: 8
|
||||
Version: 2.3.1
|
||||
Release: 5
|
||||
Summary: A simple program which checks Python source files for errors
|
||||
License: MIT
|
||||
URL: https://github.com/PyCQA/pyflakes
|
||||
Source0: https://files.pythonhosted.org/packages/source/p/%{name}/%{name}-%{version}.tar.gz
|
||||
Source1: http://mirrors.aliyun.com/ubuntu/ubuntu/pool/universe/p/pyflakes/pyflakes_1.6.0-1.debian.tar.xz
|
||||
Patch0001: %{name}-1.1.0-python3-man.patch
|
||||
Source0: https://files.pythonhosted.org/packages/a8/0f/0dc480da9162749bf629dca76570972dd9cce5bedc60196a3c912875c87d/pyflakes-2.3.1.tar.gz
|
||||
BuildArch: noarch
|
||||
BuildRequires: python2-devel >= 2.7 python2-setuptools
|
||||
|
||||
Patch0001: 0001-remove-old-and-unused-tracing-code-625.patch
|
||||
Patch0002: 0001-add-support-for-match-statement-630.patch
|
||||
Patch0003: 0001-Detect-typing-module-attributes-with-import-typing-a.patch
|
||||
Patch0004: 0001-fix-typo-annoation-annotation-636.patch
|
||||
|
||||
%description
|
||||
This is a safe program which analyze programs and detects various errors.\
|
||||
It works by parsing the source file and check for error.\
|
||||
@ -44,7 +47,7 @@ Summary: help document and man info
|
||||
Help document and man info for pyflakes package
|
||||
|
||||
%prep
|
||||
%autosetup -a 1 -p1
|
||||
%autosetup -n pyflakes-2.3.1 -p1
|
||||
|
||||
%build
|
||||
%py2_build
|
||||
@ -56,10 +59,7 @@ Help document and man info for pyflakes package
|
||||
mv %{buildroot}%{_bindir}/pyflakes %{buildroot}%{_bindir}/pyflakes-%{python3_version}
|
||||
ln -s pyflakes-%{python3_version} %{buildroot}%{_bindir}/pyflakes-3
|
||||
mkdir -p %{buildroot}%{_mandir}/man1
|
||||
cp debian/pyflakes3.1 %{buildroot}%{_mandir}/man1/pyflakes-%{python3_version}.1
|
||||
chmod 644 %{buildroot}%{_mandir}/man1/pyflakes-%{python3_version}.1
|
||||
touch %{buildroot}%{_mandir}/man1/pyflakes-%{python3_version}.1
|
||||
ln -s pyflakes-%{python3_version}.1 %{buildroot}%{_mandir}/man1/pyflakes-3.1
|
||||
ln -s pyflakes-3 %{buildroot}%{_bindir}/python3-pyflakes
|
||||
ln -s pyflakes-3.1 %{buildroot}%{_mandir}/man1/python3-pyflakes.1
|
||||
|
||||
@ -67,10 +67,7 @@ ln -s pyflakes-3.1 %{buildroot}%{_mandir}/man1/python3-pyflakes.1
|
||||
mv %{buildroot}%{_bindir}/pyflakes %{buildroot}%{_bindir}/pyflakes-%{python2_version}
|
||||
ln -s pyflakes-%{python2_version} %{buildroot}%{_bindir}/pyflakes-2
|
||||
mkdir -p %{buildroot}%{_mandir}/man1
|
||||
cp debian/pyflakes.1 %{buildroot}%{_mandir}/man1/pyflakes-%{python2_version}.1
|
||||
chmod 644 %{buildroot}%{_mandir}/man1/pyflakes-%{python2_version}.1
|
||||
touch %{buildroot}%{_mandir}/man1/pyflakes-%{python2_version}.1
|
||||
ln -s pyflakes-%{python2_version}.1 %{buildroot}%{_mandir}/man1/pyflakes-2.1
|
||||
ln -s pyflakes-3 %{buildroot}%{_bindir}/pyflakes
|
||||
ln -s pyflakes-3.1 %{buildroot}%{_mandir}/man1/pyflakes.1
|
||||
|
||||
@ -93,11 +90,26 @@ ln -s pyflakes-3.1 %{buildroot}%{_mandir}/man1/pyflakes.1
|
||||
%{_bindir}/pyflakes
|
||||
|
||||
%files help
|
||||
%doc AUTHORS NEWS.txt README.rst
|
||||
%doc AUTHORS README.rst
|
||||
%{_mandir}/man1/*
|
||||
|
||||
|
||||
%changelog
|
||||
* Mon Dec 25 2023 liubo <liubo1@xfusion.com> - 2.3.1-5
|
||||
- fix typo: annoation -> annotation (#636)
|
||||
|
||||
* Mon Dec 18 2023 liubo <liubo1@xfusion.com> - 2.3.1-4
|
||||
- Detect typing module attributes with 'import typing as <name>
|
||||
|
||||
* Thu Nov 23 2023 liubo <liubo1@xfusion.com> - 2.3.1-3
|
||||
- add support for match statement
|
||||
|
||||
* Wed Nov 22 2023 liubo <liubo1@xfusion.com> - 2.3.1-2
|
||||
- remove old and unused "tracing"
|
||||
|
||||
* Tue Oct 24 2023 luxuexian <luxuexian@huawei.com> - 2.3.1-1
|
||||
- Update to version 2.3.1
|
||||
|
||||
* Fri Nov 15 2019 zhujunhao <zhujunhao5@huawei.com> - 2.0.0-8
|
||||
- package init
|
||||
|
||||
|
||||
4
pyflakes.yaml
Normal file
4
pyflakes.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
version_control: pypi
|
||||
src_repo: pyflakes
|
||||
tag_prefix: "^v"
|
||||
separator: "."
|
||||
Loading…
x
Reference in New Issue
Block a user