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

Commit fa98f97

Browse files
committed
Fixed execution of mypy.
1 parent 3f663e5 commit fa98f97

3 files changed

Lines changed: 67 additions & 55 deletions

File tree

.github/workflows/Pipeline.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ jobs:
136136
- name: Check Static Typing
137137
continue-on-error: true
138138
run: |
139-
pwd
140-
mypy --html-report htmlmypy -m pyTooling.TerminalUI
139+
cd pyTooling
140+
mypy --html-report ../htmlmypy -p TerminalUI
141141
142142
- name: 📤 Upload 'Static Typing Report' artifact
143143
continue-on-error: true
@@ -382,12 +382,12 @@ jobs:
382382
needs:
383383
- BuildTheDocs
384384
- Coverage
385-
# - StaticTypeCheck
385+
- StaticTypeCheck
386386

387387
env:
388388
DOC: ${{ needs.BuildTheDocs.outputs.artifact }}
389389
COVERAGE: ${{ needs.Coverage.outputs.artifact }}
390-
# TYPING: ${{ needs.StaticTypeCheck.outputs.artifact }}
390+
TYPING: ${{ needs.StaticTypeCheck.outputs.artifact }}
391391
outputs:
392392
artifact: ${{ env.ARTIFACT }}
393393

@@ -407,11 +407,11 @@ jobs:
407407
name: ${{ env.COVERAGE }}
408408
path: public/coverage
409409

410-
# - name: 📥 Download artifacts '${{ env.TYPING }}' from 'StaticTypeCheck' job
411-
# uses: actions/download-artifact@v2
412-
# with:
413-
# name: ${{ env.TYPING }}
414-
# path: public/typing
410+
- name: 📥 Download artifacts '${{ env.TYPING }}' from 'StaticTypeCheck' job
411+
uses: actions/download-artifact@v2
412+
with:
413+
name: ${{ env.TYPING }}
414+
path: public/typing
415415

416416
- name: '📓 Publish site to GitHub Pages'
417417
if: github.event_name != 'pull_request'
@@ -431,13 +431,13 @@ jobs:
431431
runs-on: ubuntu-latest
432432
needs:
433433
- Coverage
434-
# - StaticTypeCheck
434+
- StaticTypeCheck
435435
- BuildTheDocs
436436
- PublishToGitHubPages
437437

438438
env:
439439
COVERAGE: ${{ needs.Coverage.outputs.artifact }}
440-
# TYPING: ${{ needs.StaticTypeCheck.outputs.artifact }}
440+
TYPING: ${{ needs.StaticTypeCheck.outputs.artifact }}
441441
DOC: ${{ needs.BuildTheDocs.outputs.artifact }}
442442

443443
steps:
@@ -447,4 +447,4 @@ jobs:
447447
name: |
448448
${{ env.COVERAGE }}
449449
${{ env.DOC }}
450-
# ${{ env.TYPING }}
450+
${{ env.TYPING }}

pyTooling/TerminalUI/__init__.py

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#
3232
from enum import Enum, unique
3333
from platform import system as platform_system
34+
from typing import NoReturn, Tuple
3435

3536
from pyTooling.Decorators import export
3637
from pyTooling.MetaClasses import Singleton
@@ -95,7 +96,7 @@ class Terminal:
9596
_width : int = None #: Terminal width in characters
9697
_height : int = None #: Terminal height in characters
9798

98-
def __init__(self):
99+
def __init__(self) -> None:
99100
"""
100101
Initialize a terminal.
101102
@@ -108,7 +109,7 @@ def __init__(self):
108109
(self._width, self._height) = self.GetTerminalSize()
109110

110111
@classmethod
111-
def initColors(cls):
112+
def initColors(cls) -> None:
112113
"""Initialize the terminal for color support by colorama."""
113114
try:
114115
from colorama import init
@@ -118,7 +119,7 @@ def initColors(cls):
118119
pass
119120

120121
@classmethod
121-
def deinitColors(cls):
122+
def deinitColors(cls) -> None:
122123
"""Uninitialize the terminal for color support by colorama."""
123124
try:
124125
from colorama import deinit
@@ -128,18 +129,18 @@ def deinitColors(cls):
128129
pass
129130

130131
@classmethod
131-
def fatalExit(cls, returnCode:int =0):
132+
def fatalExit(cls, returnCode:int =0) -> NoReturn:
132133
"""Exit the terminal application by uninitializing color support and returning a fatal exit code."""
133134
cls.exit(cls.FATAL_EXIT_CODE if returnCode == 0 else returnCode)
134135

135136
@classmethod
136-
def exit(cls, returnCode:int =0):
137+
def exit(cls, returnCode:int =0) -> NoReturn:
137138
"""Exit the terminal application by uninitializing color support and returning an exit code."""
138139
cls.deinitColors()
139140
exit(returnCode)
140141

141142
@classmethod
142-
def versionCheck(cls, version):
143+
def versionCheck(cls, version) -> None:
143144
"""Check if the used Python interpreter fulfills the minimum version requirements."""
144145

145146
from sys import version_info
@@ -159,7 +160,7 @@ def versionCheck(cls, version):
159160
cls.exit(1)
160161

161162
@classmethod
162-
def printException(cls, ex):
163+
def printException(cls, ex) -> NoReturn:
163164
"""Prints an exception of type :exc:`Exception`."""
164165

165166
from traceback import print_tb, walk_tb
@@ -190,7 +191,7 @@ def printException(cls, ex):
190191
cls.exit(1)
191192

192193
@classmethod
193-
def printNotImplementedError(cls, ex):
194+
def printNotImplementedError(cls, ex) -> NoReturn:
194195
"""Prints a not-implemented exception of type :exc:`NotImplementedError`."""
195196

196197
from traceback import walk_tb
@@ -213,7 +214,7 @@ def printNotImplementedError(cls, ex):
213214
cls.exit(1)
214215

215216
@classmethod
216-
def printExceptionBase(cls, ex):
217+
def printExceptionBase(cls, ex) -> NoReturn:
217218
cls.initColors()
218219

219220
print("{RED}FATAL: A known but unhandled exception reached the topmost exception handler!{NOCOLOR}".format(**cls.Foreground))
@@ -225,17 +226,17 @@ def printExceptionBase(cls, ex):
225226
cls.exit(1)
226227

227228
@property
228-
def Width(self):
229+
def Width(self) -> int:
229230
"""Returns the current terminal window's width."""
230231
return self._width
231232

232233
@property
233-
def Height(self):
234+
def Height(self) -> int:
234235
"""Returns the current terminal window's height."""
235236
return self._height
236237

237238
@staticmethod
238-
def GetTerminalSize():
239+
def GetTerminalSize() -> Tuple[int, int]:
239240
"""
240241
Returns the terminal size as tuple (width, height) for Windows, Mac OS
241242
(Darwin), Linux, cygwin (Windows), MinGW32/64 (Windows).
@@ -257,7 +258,7 @@ def GetTerminalSize():
257258
return size
258259

259260
@staticmethod
260-
def __GetTerminalSizeOnWindows():
261+
def __GetTerminalSizeOnWindows() -> Tuple[int, int]:
261262
"""Returns the current terminal window's size for Windows."""
262263

263264
try:
@@ -278,7 +279,7 @@ def __GetTerminalSizeOnWindows():
278279
return Terminal.__GetTerminalSizeWithTPut()
279280

280281
@staticmethod
281-
def __GetTerminalSizeWithTPut():
282+
def __GetTerminalSizeWithTPut() -> Tuple[int, int]:
282283
from shlex import split as shlex_split
283284
from subprocess import check_output
284285

@@ -290,7 +291,7 @@ def __GetTerminalSizeWithTPut():
290291
pass
291292

292293
@staticmethod
293-
def __GetTerminalSizeOnLinux():
294+
def __GetTerminalSizeOnLinux() -> Tuple[int, int]:
294295
"""Returns the current terminal window's size for Linux."""
295296

296297
import os
@@ -343,12 +344,23 @@ class Severity(Enum):
343344
def __hash__(self):
344345
return hash(self.name)
345346

346-
def __eq__(self, other): return self.value == other.value
347-
def __ne__(self, other): return self.value != other.value
348-
def __lt__(self, other): return self.value < other.value
349-
def __le__(self, other): return self.value <= other.value
350-
def __gt__(self, other): return self.value > other.value
351-
def __ge__(self, other): return self.value >= other.value
347+
def __eq__(self, other):
348+
return self.value == other.value
349+
350+
def __ne__(self, other):
351+
return self.value != other.value
352+
353+
def __lt__(self, other):
354+
return self.value < other.value
355+
356+
def __le__(self, other):
357+
return self.value <= other.value
358+
359+
def __gt__(self, other):
360+
return self.value > other.value
361+
362+
def __ge__(self, other):
363+
return self.value >= other.value
352364

353365

354366
@export
@@ -367,7 +379,7 @@ class Line:
367379
Severity.DryRun: "DRYRUN: {message}"
368380
} #: Terminal messages formatting rules
369381

370-
def __init__(self, message, severity=Severity.Normal, indent=0, appendLinebreak=True):
382+
def __init__(self, message, severity=Severity.Normal, indent=0, appendLinebreak=True) -> None:
371383
"""Constructor for a new ``Line`` object."""
372384

373385
self._severity = severity
@@ -377,25 +389,25 @@ def __init__(self, message, severity=Severity.Normal, indent=0, appendLinebreak=
377389

378390

379391
@property
380-
def Severity(self):
392+
def Severity(self) -> Severity:
381393
"""Return the line's severity level."""
382394
return self._severity
383395

384396
@property
385-
def Indent(self):
397+
def Indent(self) -> int:
386398
"""Return the line's indentation level."""
387399
return self._indent
388400

389401
@property
390-
def Message(self):
402+
def Message(self) -> str:
391403
"""Return the indented line."""
392404
return (" " * self._indent) + self._message
393405

394-
def IndentBy(self, indent):
406+
def IndentBy(self, indent) -> None:
395407
"""Increase a line's indentation level."""
396408
self._indent += indent
397409

398-
def __str__(self):
410+
def __str__(self) -> str:
399411
"""Returns a formatted version of a ``Line`` objects as a string."""
400412
return self._LOG_MESSAGE_FORMAT__[self._severity].format(message=self._message)
401413

@@ -406,15 +418,15 @@ class ILineTerminal:
406418

407419
_terminal = None
408420

409-
def __init__(self, terminal=None):
421+
def __init__(self, terminal=None) -> None:
410422
"""MixIn initializer."""
411423

412424
self._terminal = terminal
413425

414426
# FIXME: Alter methods if a terminal is present or set dummy methods
415427

416428
@property
417-
def Terminal(self):
429+
def Terminal(self) -> Terminal:
418430
"""Return the local terminal instance."""
419431
return self._terminal
420432

@@ -496,7 +508,7 @@ def WriteDryRun(self, *args, condition=True, **kwargs):
496508

497509
@export
498510
class LineTerminal(Terminal, ILineTerminal, metaclass=Singleton):
499-
def __init__(self, verbose=False, debug=False, quiet=False, writeToStdOut=True):
511+
def __init__(self, verbose=False, debug=False, quiet=False, writeToStdOut=True) -> None:
500512
"""Initializer of a line based terminal interface."""
501513

502514
Terminal.__init__(self)
@@ -523,34 +535,34 @@ def __init__(self, verbose=False, debug=False, quiet=False, writeToStdOut=True):
523535
self._warningCounter = 0
524536

525537
@property
526-
def Verbose(self):
538+
def Verbose(self) -> bool:
527539
"""Returns true, if verbose messages are enabled."""
528540
return self._verbose
529541

530542
@property
531-
def Debug(self):
543+
def Debug(self) -> bool:
532544
"""Returns true, if debug messages are enabled."""
533545
return self._debug
534546

535547
@property
536-
def Quiet(self):
548+
def Quiet(self) -> bool:
537549
"""Returns true, if quiet mode is enabled."""
538550
return self._quiet
539551

540552
@property
541-
def LogLevel(self):
553+
def LogLevel(self) -> Severity:
542554
"""Return the current minimal severity level for writing."""
543555
return self._WriteLevel
544556
@LogLevel.setter
545-
def LogLevel(self, value):
557+
def LogLevel(self, value: Severity) -> None:
546558
"""Set the minimal severity level for writing."""
547559
self._WriteLevel = value
548560

549561
@property
550-
def BaseIndent(self):
562+
def BaseIndent(self) -> int:
551563
return self._baseIndent
552564
@BaseIndent.setter
553-
def BaseIndent(self, value):
565+
def BaseIndent(self, value: int) -> None:
554566
self._baseIndent = value
555567

556568
_LOG_MESSAGE_FORMAT__ = {
@@ -565,14 +577,14 @@ def BaseIndent(self, value):
565577
Severity.Debug: "{DARK_GRAY}{message}{NOCOLOR}"
566578
} #: Message formatting rules.
567579

568-
def ExitOnPreviousErrors(self):
580+
def ExitOnPreviousErrors(self) -> None:
569581
"""Exit application if errors have been printed."""
570582

571583
if self._errorCounter > 0:
572584
self.WriteFatal("Too many errors in previous steps.")
573585
self.fatalExit()
574586

575-
def ExitOnPreviousWarnings(self):
587+
def ExitOnPreviousWarnings(self) -> None:
576588
"""Exit application if warnings have been printed."""
577589

578590
if self._warningCounter > 0:
@@ -590,7 +602,7 @@ def WriteLine(self, line : Line):
590602
else:
591603
return False
592604

593-
def TryWriteLine(self, line):
605+
def TryWriteLine(self, line) -> bool:
594606
return (line.Severity >= self._WriteLevel)
595607

596608
def WriteFatal(self, message, indent=0, appendLinebreak=True, immediateExit=True):

tests/unit/TerminalUI.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050

5151
class Application(LineTerminal):
52-
def __init__(self):
52+
def __init__(self) -> None:
5353
super().__init__(verbose=True, debug=True, quiet=False)
5454

5555
LineTerminal.FATAL_EXIT_CODE = 0
@@ -61,10 +61,10 @@ class Terminal(TestCase):
6161
def setUp(self) -> None:
6262
self.app = Application()
6363

64-
def test_Version(self):
64+
def test_Version(self) -> None:
6565
Application.versionCheck((3, 6, 0))
6666

67-
def test_Write(self):
67+
def test_Write(self) -> None:
6868
self.app.WriteQuiet("This is a quiet message.")
6969
self.app.WriteNormal("This is a normal message.")
7070
self.app.WriteInfo("This is a info message.")

0 commit comments

Comments
 (0)