|
1 | 1 | README |
2 | 2 | ====== |
3 | 3 |
|
4 | | -.. note:: |
5 | | - |
6 | | - The default branch is now :code:`main`. If your clone contains the old :code:`master` branch, please rename and repoint your :code:`master` remote to :code:`main`. |
7 | | - |
| 4 | +NOTE: The default branch is now :code:`main`. If your clone contains the old :code:`master` branch, please rename and repoint your :code:`master` remote to :code:`main`. |
8 | 5 |
|
9 | 6 | This is an **experimental project** for exploring the analysis of the complexity of Python project source code in terms of `cyclomatic complexity <https://en.wikipedia.org/wiki/Cyclomatic_complexity>`_ via directed graph representations of the associated `CPython bytecode instructions <https://docs.python.org/3/library/dis.html#python-bytecode-instructions>`_. These directed graph representations have structural properties that can describe the complexity of the source code, which can be useful in a variety of applications, including unit testing. |
10 | 7 |
|
@@ -42,8 +39,9 @@ Some examples are given below, to illustrate the concept and measures of cycloma |
42 | 39 | First, consider the following simple Python implementation of the `sign function <https://en.wikipedia.org/wiki/Sign_function>`_, for determining whether a given number (integer or float) is negative, zero, or positive: |
43 | 40 |
|
44 | 41 | .. code-block:: python |
| 42 | + import typing |
45 | 43 |
|
46 | | - def sign(x: int | float) -> typing.Literal[-1, 0, 1]: |
| 44 | + def sign(x: typing.Union[int, float]) -> int: |
47 | 45 | if x < 0: |
48 | 46 | return -1 |
49 | 47 | if x == 0: |
@@ -99,7 +97,7 @@ Here's an iPython session using the sign function as an example. |
99 | 97 |
|
100 | 98 | In [1]: from ccm.complexity import * |
101 | 99 |
|
102 | | - In [2]: def sign(x) : |
| 100 | + In [2]: def sign(x: typing.Union[int, float]) -> int: |
103 | 101 | ...: if x < 0: |
104 | 102 | ...: return -1 |
105 | 103 | ...: if x == 0: |
@@ -258,7 +256,7 @@ The second example is an identity function for arbitrary arguments, with just a |
258 | 256 |
|
259 | 257 | In [29]: from ccm.xdis import dis as xdis |
260 | 258 |
|
261 | | - In [30]: def identity(x): |
| 259 | + In [30]: def identity(x: typing.Any) -> typing.Any: |
262 | 260 | ...: return x |
263 | 261 |
|
264 | 262 | In [30]: xdis(identity) |
@@ -291,7 +289,7 @@ Here is a third example involving a function with a decision point involving a c |
291 | 289 |
|
292 | 290 | .. code-block:: python |
293 | 291 |
|
294 | | - In [39]: def nonzero(x): |
| 292 | + In [39]: def nonzero(x: typing.Union[int, float]) -> bool: |
295 | 293 | ...: if x < 0 or x > 0 : |
296 | 294 | ...: return True |
297 | 295 | ...: return False |
|
0 commit comments