Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 0ce2492

Browse files
authored
Fix type hinting in README code samples
1 parent 886bd42 commit 0ce2492

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

README.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
README
22
======
33

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`.
85

96
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.
107

@@ -42,8 +39,9 @@ Some examples are given below, to illustrate the concept and measures of cycloma
4239
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:
4340

4441
.. code-block:: python
42+
import typing
4543
46-
def sign(x: int | float) -> typing.Literal[-1, 0, 1]:
44+
def sign(x: typing.Union[int, float]) -> int:
4745
if x < 0:
4846
return -1
4947
if x == 0:
@@ -99,7 +97,7 @@ Here's an iPython session using the sign function as an example.
9997
10098
In [1]: from ccm.complexity import *
10199
102-
In [2]: def sign(x) :
100+
In [2]: def sign(x: typing.Union[int, float]) -> int:
103101
...: if x < 0:
104102
...: return -1
105103
...: if x == 0:
@@ -258,7 +256,7 @@ The second example is an identity function for arbitrary arguments, with just a
258256
259257
In [29]: from ccm.xdis import dis as xdis
260258
261-
In [30]: def identity(x):
259+
In [30]: def identity(x: typing.Any) -> typing.Any:
262260
...: return x
263261
264262
In [30]: xdis(identity)
@@ -291,7 +289,7 @@ Here is a third example involving a function with a decision point involving a c
291289

292290
.. code-block:: python
293291
294-
In [39]: def nonzero(x):
292+
In [39]: def nonzero(x: typing.Union[int, float]) -> bool:
295293
...: if x < 0 or x > 0 :
296294
...: return True
297295
...: return False

0 commit comments

Comments
 (0)