• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pyta-uoft / pyta / 19300648625

12 Nov 2025 02:22PM UTC coverage: 93.909% (-0.4%) from 94.325%
19300648625

push

github

web-flow
Optimized performance for 'test_examples.py' (#1251)

8 of 8 new or added lines in 2 files covered. (100.0%)

16 existing lines in 7 files now uncovered.

3515 of 3743 relevant lines covered (93.91%)

17.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.45
/python_ta/patches/checkers.py
1
"""Patch pylint checker behaviour."""
2

3
from pylint.checkers.base import NameChecker
20✔
4
from pylint.checkers.classes import ClassChecker
20✔
5
from pylint.checkers.utils import node_frame_class
20✔
6

7
from python_ta.utils import _is_in_main
20✔
8

9

10
def patch_checkers():
20✔
11
    """Run patches to modify built-in pylint checker behaviour."""
12
    _override_check_protected_attribute_access()
20✔
13
    _override_check_invalid_name_in_main()
20✔
14

15

16
def _override_check_protected_attribute_access():
20✔
17
    """Override protected-member-access check.
18

19
    We find pylint's default protected-member-access check too restrictive in
20
    method bodies; it only allows protected attribute access on the 'self'
21
    parameter (and from the class itself).
22

23
    We change this behaviour to allow access to any protected attribute that is
24
    defined for this class. (This leads to false negatives unless we combine
25
    this with type inference, but we're okay with that.)
26
    """
27
    old_check_protected_attribute_access = ClassChecker._check_protected_attribute_access
20✔
28

29
    def _check(self, node):
20✔
30
        attrname = node.attrname
20✔
31
        klass = node_frame_class(node)
20✔
32
        if klass is None or (
20✔
33
            attrname not in klass.instance_attrs
34
            and attrname not in (m.name for m in klass.methods())
35
        ):
36
            old_check_protected_attribute_access(self, node)
20✔
37

38
    ClassChecker._check_protected_attribute_access = _check
20✔
39

40

41
def _override_check_invalid_name_in_main():
20✔
42
    """Override invalid-name check for variables in main block.
43

44
    pylint normally complains about variable names in the main block
45
    that aren't in ALL_CAPS -- in other words, it assumes that all such
46
    variables should be constants. We disable this check here so that
47
    non-constant variable names are permitted (encourages experimentation
48
    in the main block).
49
    """
50
    old_visit_assignname = NameChecker.visit_assignname
20✔
51

52
    def patched_visit_assignname(self, node):
20✔
53
        if _is_in_main(node):
20✔
UNCOV
54
            self._check_name("variable", node.name, node)
×
55
        else:
56
            old_visit_assignname(self, node)
20✔
57

58
    NameChecker.visit_assignname = patched_visit_assignname
20✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc