Skip to content

Commit 5240356

Browse files
authored
Use python3.7 dataclass in a few places. NFC (#25191)
1 parent e1df9b5 commit 5240356

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

emcc.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import sys
3030
import time
3131
import tarfile
32+
from dataclasses import dataclass
3233
from enum import Enum, auto, unique
3334
from subprocess import PIPE
3435

@@ -89,6 +90,7 @@ class Mode(Enum):
8990
COMPILE_AND_LINK = auto()
9091

9192

93+
@dataclass
9294
class LinkFlag:
9395
"""Used to represent a linker flag.
9496
@@ -97,9 +99,8 @@ class LinkFlag:
9799
98100
A list of these is return by separate_linker_flags.
99101
"""
100-
def __init__(self, value, is_file):
101-
self.value = value
102-
self.is_file = is_file
102+
value: str
103+
is_file: int
103104

104105

105106
class EmccState:

emsymbolizer.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
# Separate DWARF is not supported yet.
1515

1616
import argparse
17+
from dataclasses import dataclass
1718
import json
1819
import re
1920
import subprocess
2021
import sys
22+
from typing import Optional
23+
2124
from tools import shared
2225
from tools import webassembly
2326

@@ -30,12 +33,12 @@ class Error(BaseException):
3033

3134

3235
# Class to treat location info in a uniform way across information sources.
36+
@dataclass
3337
class LocationInfo:
34-
def __init__(self, source=None, line=0, column=0, func=None):
35-
self.source = source
36-
self.line = line
37-
self.column = column
38-
self.func = func
38+
source: Optional[str] = None
39+
line: int = 0
40+
column: int = 0
41+
func: Optional[str] = None
3942

4043
def print(self):
4144
source = self.source if self.source else '??'
@@ -100,12 +103,12 @@ def get_sourceMappingURL_section(module):
100103

101104

102105
class WasmSourceMap:
106+
@dataclass
103107
class Location:
104-
def __init__(self, source=None, line=0, column=0, func=None):
105-
self.source = source
106-
self.line = line
107-
self.column = column
108-
self.func = func
108+
source: Optional[str] = None
109+
line: int = 0
110+
column: int = 0
111+
func: Optional[str] = None
109112

110113
def __init__(self):
111114
self.version = None

tools/extract_metadata.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import logging
77
from typing import List, Dict
8+
from dataclasses import dataclass
89

910
from . import webassembly, utils
1011
from .webassembly import OpCode, AtomicOpCode, MemoryOpCode
@@ -299,6 +300,7 @@ def get_string_at(module, address):
299300
return data_to_string(data[offset:str_end])
300301

301302

303+
@dataclass(init=False)
302304
class Metadata:
303305
imports: List[str]
304306
export: List[str]
@@ -314,9 +316,6 @@ class Metadata:
314316
tag_exports: List[str]
315317
all_exports: List[str]
316318

317-
def __init__(self):
318-
pass
319-
320319

321320
def extract_metadata(filename):
322321
em_js_funcs = {}

tools/file_packager.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
import posixpath
7777
import shutil
7878
import sys
79+
from dataclasses import dataclass
7980
from subprocess import PIPE
8081
from textwrap import dedent
8182
from typing import List
@@ -123,12 +124,12 @@ def __init__(self):
123124
self.export_es6 = False
124125

125126

127+
@dataclass
126128
class DataFile:
127-
def __init__(self, srcpath, dstpath, mode, explicit_dst_path):
128-
self.srcpath = srcpath
129-
self.dstpath = dstpath
130-
self.mode = mode
131-
self.explicit_dst_path = explicit_dst_path
129+
srcpath: str
130+
dstpath: str
131+
mode: str
132+
explicit_dst_path: bool
132133

133134

134135
options = Options()

0 commit comments

Comments
 (0)